package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kaili.basic.mapper.StrategySiteMapper;
import com.kaili.basic.pojo.entity.StrategyMainEntity;
import com.kaili.basic.pojo.entity.StrategySiteEntity;
import com.kaili.basic.service.IStrategySiteService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* 设备策略 service实现类
* @author:zhangjl
* @Time: 2019-07-24
* @Copyright: ©  杭州凯立通信有限公司 版权所有
* @Warning: 本内容仅限于公司内部传阅,禁止外泄或用于其它商业目的
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class StrategySiteServiceImpl extends ServiceImpl<StrategySiteMapper, StrategySiteEntity>  implements IStrategySiteService {

    @Override
    public boolean add(StrategyMainEntity entity) {
        List<StrategySiteEntity> list = entity.getStrategySiteDetail();
        for (StrategySiteEntity siteEntity :list){
            siteEntity.setStrategy_id(entity.getId());
        }
        this.insertBatch(list);

        return true;
    }

    @Override
    public boolean modify(StrategyMainEntity entity) {
        //1、删除设备策略
        this.del(entity.getId());
        //2、新增设备类
        this.add(entity);

        return true;
    }

    @Override
    public boolean del(Integer id) {
        Wrapper<StrategySiteEntity> wrapper = new EntityWrapper<>();
        wrapper.where("strategy_id ={0}", id);
        this.delete(wrapper);
        return true;
    }

}
